using System;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DataTableProvider
/// </summary>
public partial class SQLServerProviders
{
    
    public DataTable GetDataTable( 
    string[] parameterCollection, 
    string[] valueCollection,
    string commandText, CommandType commandType)
	{
        errorMessage = "";
        DataTable dataTable = new DataTable();
        try
        {
            OpenConnection();
            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = commandText;
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType =commandType;
            AddParameters( sqlCommand, 
            parameterCollection,valueCollection);
            sqlDataAdapter = new SqlDataAdapter(sqlCommand);
            sqlDataAdapter.Fill(dataTable);
            CloseConnection();
        }
        catch (SqlException sql)
        {
            errorCode = sql.Number;
            errorMessage = sql.Message;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return dataTable;
	}
    public DataTable GetDataTable(
    string parameterName,
    string  valueOfPparameter,
    string commandText, CommandType commandType)
    {
        errorMessage = "";
        DataTable dataTable = new DataTable();
        try
        {
            OpenConnection();
            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = commandText;
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType = commandType;
            AddParameters(sqlCommand,
            parameterName, valueOfPparameter);
            sqlDataAdapter = new SqlDataAdapter(sqlCommand);
            sqlDataAdapter.Fill(dataTable);
            CloseConnection();
        }
        catch (SqlException sql)
        {
            errorCode = sql.Number;
            errorMessage = sql.Message;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return dataTable;
    }
    public DataTable GetDataTable(    
    string commandText, CommandType commandType)
    {
        errorMessage = "";
        DataTable dataTable = new DataTable();
        try
        {
            OpenConnection();
            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = commandText;
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType = commandType;            
            sqlDataAdapter = new SqlDataAdapter(sqlCommand);
            sqlDataAdapter.Fill(dataTable);
            CloseConnection();
        }
        catch (SqlException sql)
        {
            errorCode = sql.Number;
            errorMessage = sql.Message;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return dataTable;
    }
    public DataTable GetDataTable(
    string commandText, CommandType commandType, int startRecord, int maxRecord)
    {
        errorMessage = "";
        DataTable dataTable = new DataTable();
        try
        {
            OpenConnection();
            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = commandText;
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType = commandType;
            sqlDataAdapter = new SqlDataAdapter(sqlCommand);
            sqlDataAdapter.Fill(startRecord, maxRecord,dataTable);
            CloseConnection();
        }
        catch (SqlException sql)
        {
            errorCode = sql.Number;
            errorMessage = sql.Message;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return dataTable;
    }
}
